package game.controller;

import common.controller.base.BaseController;
import common.model.po.GLandform;
import common.model.request.base.PaginationRequest;
import common.model.response.base.Result;
import game.model.request.SaveLandformRequest;
import game.model.request.SearchLandformRequest;
import game.service.GLandformService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 地貌前端控制器
 *
 * @author 米泽鹏
 * @since 2022-02-26
 */
@Api(tags = "地貌管理")
@RestController
@RequestMapping("/game/g-landform")
public class GLandformController extends BaseController {

	@Resource
	private GLandformService service;

	@ApiOperation(value = "地貌分页查询", notes = "地貌分页查询")
	@PostMapping("/readOnly/searchLandformByPage")
	public Result<?> searchItemByPage(@ApiParam(value = "地貌分页查询请求", required = true) @RequestBody PaginationRequest<SearchLandformRequest, GLandform> request) {
		return successWithData(service.searchLandformByPage(request));
	}

	@ApiOperation(value = "地貌新增或更新", notes = "地貌新增或更新")
	@PostMapping("/saveLandform")
	public Result<?> saveLandform(@ApiParam(value = "地貌新增或更新请求", required = true) @RequestBody @Validated SaveLandformRequest request) {
		return successWithData(service.saveLandform(request));
	}

	@ApiOperation(value = "地貌删除", notes = "地貌删除")
	@DeleteMapping("/deleteLandform/{id}")
	public Result<?> deleteLandform(@ApiParam(value = "地貌id", required = true) @PathVariable Long id) {
		if (service.removeById(id)) {
			return success();
		} else {
			return error();
		}
	}

}
